package com.ssd.controller.inner;

import cn.hutool.core.bean.BeanUtil;
import com.ssd.api.payment.TradingApi;
import com.ssd.api.payment.dto.response.TradingResDTO;
import com.ssd.model.dto.TradingDTO;
import com.ssd.service.BasicPayService;
import com.ssd.service.TradingService;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 提供内部接口的控制器类，专注于交易单服务
 * @author cy
 * @version 1.0
 */
@RestController("innerTradingController")
@Api(tags = "内部接口 - 交易单服务")
@RequestMapping("/inner/tradings")
public class TradingController  implements TradingApi {

    /**
     * 用于处理交易单业务逻辑的服务
     */
    @Resource
    private TradingService tradingService;

    /**
     * 提供基础支付功能的服务
     */
    @Resource
    private BasicPayService basicPayService;

    /**
     * 根据交易单号查询交易单的交易结果
     * @param tradingOrderNo 交易单号
     * @return 交易单的交易结果数据
     */
    @GetMapping("/findTradResultByTradingOrderNo")
    @ApiOperation(value = "根据交易单号查询交易单的交易结果", notes = "根据交易单号查询交易单的交易结果")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tradingOrderNo", value = "交易单号", required = true, dataTypeClass = Long.class)
    })
    public TradingResDTO findTradResultByTradingOrderNo(@ApiParam(value = "交易单号") @RequestParam("tradingOrderNo") Long tradingOrderNo) {
        // 查询交易结果
        TradingDTO tradingDTO = basicPayService.queryTradingResult(tradingOrderNo);
        // 将查询结果转换为响应DTO
        TradingResDTO tradingResDTO = BeanUtil.toBean(tradingDTO, TradingResDTO.class);
        return tradingResDTO;
    }
}

